class Node:
    def __init__(self, x: int, next: 'Node' = None, random: 'Node' = None):
        self.val = int(x)
        self.next = next
        self.random = random

class Solution:
    def copyRandomList(self, head: 'Node') -> 'Node':
        if head is None:
            return None
        
        dt = {None:None}
        cur = head
        while cur:
            dt[cur] = Node(cur.val)
            cur = cur.next;
        
        cur = head
        while cur:
            dt[cur].next = dt[cur.next] 
            dt[cur].random = dt[cur.random]
            cur = cur.next
        return dt[head]